public without sharing class ProductOutOrInSycController {
    
	public String msg {get; private set;}

	public Boolean isErr {get; private set;}

	public Boolean isSuc {get; private set;}

	public String backId {get; private set;}

	public String syncJson {get;  set;}
	public String resJson {get;  set;}

  public String dataJson {get; private set;}
  public String saveJson {get;  set;}
	public  ProductOutOrIn__c poi {get;private set;}

  public String comcode {get ;private set;}

  public Boolean isSyc {get;private set;}

  private String queryTag = 'price';
  private String updateTag = 'refsaleprice';
  private String source = 'NC';
  private User Owner; 
  private User u ;
	public class ControllerException extends Exception {}

    public ProductOutOrInSycController() {
        	
        backId = System.currentPageReference().getParameters().get('id');
        isSyc = System.currentPageReference().getParameters().get('syc') != null ;

        poi = new ProductOutOrIn__c();
        Owner = new User();
        User u = new User();
    }

    public void init(){

      try {
           u = [select Id,Profile.Name ,SubCompany__c,CompanyName from User where Id=:UserInfo.getUserId()];
           if(u.CompanyName == null )setErr('请联系管理员维护个人档案公司(CompanyName)字段');
           comcode = u.CompanyName;
           poi = [select Id  ,Status__c ,Company__c ,BorrowType__c,IsSycToNc__c,Note__c,Destination__c,ConsigneeCall__c,UseHospital__r.AccountNumber, NCPriceDialog__c,Customer__r.AccountNumber , Owner.Name ,OwnerId from ProductOutOrIn__c where Id =:backId];
           System.debug('ProductOutOrInSycController==>'+poi);
           System.debug('ProductOutOrInSycController==>'+isSyc);
          if(isSyc){
            if(poi.BorrowType__c == '借出')return;
            syncInit(poi );
            return;
          }

          editInit(poi);

      }
      catch (Exception e) {
          ApexPages.addMessage( new ApexPages.Message(ApexPages.Severity.ERROR ,e.getMessage()));
      }
      
    	

    }

    //获取搜索字段信息
    private Map<String,List<DataUtil.FieldBean>> getSearchObject(){
      Map<String,List<DataUtil.FieldBean>> searchMap = new Map<String,List<DataUtil.FieldBean>>();

      Map<String,DataUtil.FieldBean>proMap = DataUtil.getFieldsInfo(Product__c.SObjecttype, new Set<String>{'ProductName__c','Brand__c','Spec__c','SerialNo__c','Category1__c','NCCode__c'} );
      searchMap.put('Product__c', proMap.values());
      return searchMap;
    }

    ///获取明细
    private List<BrorrowBean> getDetails(){

        List<BrorrowBean> tmp = new List<BrorrowBean>();
         for(BorrowGoodsDetail__c bgd : [select Id ,Inventory__c ,Quantity__c,ProductLine__c,Inventory__r.Brand__c,Inventory__r.NCCode__c,
          Inventory__r.Spec__c,Inventory__r.Unit__c,Inventory__r.SerialNo__c ,Inventory__r.ProductName__c,Inventory__r.Category1__c
           from BorrowGoodsDetail__c where BorrowDetail__c =: backId]){
            tmp.add(new BrorrowBean(bgd));

         }
         return tmp;



    }


    @RemoteAction
    public static List<BrorrowBean>  matchProduct(List<String> nccodes,String comcode   ){
      List<BrorrowBean> tmp = new List<BrorrowBean>();
      if(nccodes == null || nccodes.size() == 0 || comcode == null )return tmp;
      String sql  = 'select Id ,ProductName__c , Brand__c , Spec__c,SerialNo__c , NCCode__c, Unit__c, Category1__c from Product__c where   (not SealCompany__c like \'%'+comcode+'%\') ';
      sql += ' and Category0__c in ' + Label.RegentCatagory3;
      sql += ' and  NCCode__c in (\''+String.join(nccodes, '\',\'')+'\') ';
      for(Product__c p: (List<Product__c>)SQLUtil.query(sql)){
        tmp.add(new BrorrowBean(p));
      }
      return tmp; 
    }

    ///保存
    public void save(){

      msg = '';
      List<Object> saveList = (List<Object> ) JSON.deserializeUntyped(EncodingUtil.urlDecode(saveJson,'UTF-8'));

      if(saveList.size() == 0 ){
        msg = '没有数据!';
        return ;  
      }
      List<BorrowGoodsDetail__c> boList  = new List<BorrowGoodsDetail__c>();
      Set<String >boIdset = new Set<String>();
      for(Object o : saveList){
        Map<String,Object> mo = (Map<String,Object>) o  ; 
        BorrowGoodsDetail__c bo = new BorrowGoodsDetail__c();
        if(mo.get('bid') != null )bo.Id =  DataUtil.getStringValue(mo.get('bid'));
        if(bo.Id != null )boIdset.add(bo.Id);
        bo.Inventory__c =  DataUtil.getStringValue(mo.get('productId'));
        bo.Quantity__c =  DataUtil.getDecimalValue(mo.get('num'));

        bo.ProductLine__c =  DataUtil.getStringValue(mo.get('cate1'));
        if(bo.Id == null )bo.BorrowDetail__c = backId;



        boList.add(bo);
      }
      SavePoint sp = Database.setSavepoint();
      try {
          delete [select Id from BorrowGoodsDetail__c where BorrowDetail__c =:backId and Id not in : boIdset];

          if(boList.size() > 0) upsert  boList;
          msg = '保存成功!';
          isSuc = true; 
      }
      catch (Exception e) {
        Database.rollback(sp);
          msg = '保存失败!'+e.getMessage();

      }

    }

    ///从产品中选择明细
    public  void search(){
          Map<String,Object> searchMap = (Map<String,Object>) JSON.deserializeUntyped(EncodingUtil.urlDecode(resJson,'UTF-8')); 

          
          String sql  = 'select Id ,ProductName__c , Brand__c , Spec__c,SerialNo__c , NCCode__c, Unit__c, Category1__c from Product__c where  (not SealCompany__c like \'%'+u.CompanyName+'%\') ';
      sql += ' and Category0__c in ' + Label.RegentCatagory3;

        if(String.isBlank(DataUtil.getStringValue(searchMap.get('ProductName__c'))) == false) sql += ' and ProductName__c like \'%'+DataUtil.getStringValue(searchMap.get('ProductName__c'))+'%\' ';

        if(String.isBlank(DataUtil.getStringValue(searchMap.get('Brand__c'))) == false) sql += ' and Brand__c like \'%'+DataUtil.getStringValue(searchMap.get('Brand__c'))+'%\' ';

        if(String.isBlank(DataUtil.getStringValue(searchMap.get('Spec__c'))) == false) sql += ' and Spec__c like \'%'+DataUtil.getStringValue(searchMap.get('Spec__c'))+'%\' ';

        if(String.isBlank(DataUtil.getStringValue(searchMap.get('SerialNo__c'))) == false) sql += ' and SerialNo__c like \'%'+DataUtil.getStringValue(searchMap.get('SerialNo__c'))+'%\' ';
   
       // if(String.isBlank(DataUtil.getStringValue(searchMap.get('Category0__c'))) == false) sql += ' and Category0__c like \'%'+DataUtil.getStringValue(searchMap.get('Category0__c'))+'%\' ';

        if(String.isBlank(DataUtil.getStringValue(searchMap.get('Category1__c'))) == false) sql += ' and Category1__c like \'%'+DataUtil.getStringValue(searchMap.get('Category1__c'))+'%\' ';

        if(String.isBlank(DataUtil.getStringValue(searchMap.get('NCCode__c'))) == false) sql += ' and NCCode__c like \'%'+DataUtil.getStringValue(searchMap.get('NCCode__c'))+'%\' ';
          sql += ' limit 200 ';
      List<BrorrowBean> tmp = new List<BrorrowBean>();
      for(Product__c p: (List<Product__c>)SQLUtil.query(sql)){
        tmp.add(new BrorrowBean(p));
      }

      dataJson = EncodingUtil.urlEncode(JSON.serialize(tmp), 'UTF-8');

    }

    ///置空变量
    public void setNil(){
        resJson = '[]';
        dataJson = '[]';
        syncJson = '{}';
    }
    ///添加产品编辑页面初始化
    private void  editInit(ProductOutOrIn__c po ){
        try{

          if(po.Status__c == '申请中'|| po.Status__c == '已批准')setErr(po.Status__c +',不能修改!');
            Map<String,Object> dataMap = new Map<String ,Object>();
           
          dataMap.put('detail',getDetails());
          dataMap.put('searchObject',getSearchObject());
          System.debug('ProductOutOrInSycController==>'+dataMap);
          dataJson = EncodingUtil.urlEncode(JSON.serialize(dataMap), 'UTF-8');
        }catch(Exception e ){

          ApexPages.addMessage( new ApexPages.Message(ApexPages.Severity.ERROR ,e.getMessage()));

        }
    }
    ////同步NC 页面初始化
    private void syncInit(ProductOutOrIn__c po ){
        try{

          if(po.Status__c != '已批准')setErr('未审批通过不能同步!');
          if(po.BorrowType__c != '未定价先发货' )setErr('借货类型不是未定价先发货,不能同步!');
          if(po.IsSycToNc__c)setErr('已同步到NC请不要重复同步!');

          User u = [select Id,Profile.Name from User where Id=:UserInfo.getUserId()];

          Owner  = [select Name , Manager.Name from User where Id=: po.OwnerId ];

          if(Owner.Manager.Name == null ) setErr('请维护所有人的经理!');

          if(u.Profile.Name != '系统管理员' && u.Profile.Name !=  '销售管理部助理' && u.Profile.Name !=  '呼叫中心订单专员')setErr('没有权限!');

          Set<String> nccodes = new Set<String>();
           List<BorrowGoodsDetail__c> bgList = [select Inventory__r.NCCode__c from  BorrowGoodsDetail__c where BorrowDetail__c =:backId  ];
          for( BorrowGoodsDetail__c bg : bgList){
             if(bg.Inventory__r.NCCode__c  != null )nccodes.add(bg.Inventory__r.NCCode__c );
           }
          Map<String,Object> dataMap  = new Map<String,Object>();
          dataMap.put('tag',queryTag);
          dataMap.put('source',source);
          dataMap.put('invc',nccodes);
          dataMap.put('cust',po.Customer__r.AccountNumber);

          dataJson =EncodingUtil.urlEncode(JSON.serialize(dataMap), 'UTF-8') ;

        }catch(Exception e ){

          ApexPages.addMessage( new ApexPages.Message(ApexPages.Severity.ERROR ,e.getMessage()));

        }
    }
    private void checkNull(Object o,String message ){
    	if(o == null || String.isBlank( String.valueOf(o)) )  throw new ControllerException(message);
    }

    //获取价目表
    public void getJmcode(){

    	String url = Label.queryResposityURL;

    	String sql = ' select cpricetariffcode jmcode, cpricetariffname jmname ,b.unitcode corpcode  from prm_tariff  a left join bd_corp b on a.pk_corp = b.pk_corp ';
       	sql = '{"data":" '+ sql+'"}';
      	System.debug(sql);
        //请求

        HttpRequest req = new HttpRequest();
        req.setBody(sql);
        req.setMethod('POST');
        req.setHeader('Content-Type','text/plain');
        req.setEndpoint(url);
        HttpResponse res = Utils.postRequest(req, 2);
      ///返回结果处理
        if (res.getStatusCode() == 200) {
          	System.debug(res.getBody());
          	Map<String,Object> r = null;
              //如果是测试
                if(Test.isRunningTest()){
                  Map<String,Object>  resBody= new Map<String,Object>();
                  resBody.put('code','0');
                  resBody.put('result','{\"result_msg\":\"查询成功！\",\"result\":1,\"data\":[{\"nccode\":\"111\",\"company\":\"111\",\"djh\":\"111\",\"djdate\":\"111\",\"signdate\":\"111\",\"termaccount\":\"111\",\"payaccount\":\"111\",\"xydqr\":\"111\",\"ye\":\"111\",\"psncode\":\"111\",\"psnname\":\"111\",\"prodlinecode\":\"111\",\"prodlinename\":\"111\",\"djrq\":\"111\",\"djbh\":\"111\",\"currtypename\":\"111\"}]}');
                    r =  resBody;

                }else{

                  r= (Map<String,Object> ) JSON.deserializeUntyped(res.getBody());

                }
          if(r.get('code') == 0 || r.get('code') == '0'){
             	Map<String,Object> rs = (Map<String,Object>) JSON.deserializeUntyped(((String)r.get('result')));
              	if( rs.get('result') == 1 ){

              		resJson = EncodingUtil.urlEncode(JSON.serialize( rs.get('data')), 'UTF-8') ;

               }else{

                 	msg = String.valueOf(rs.get('result_msg'));

               }

        }else{
          	msg = '获取价目表信息失败 : '+String.valueOf(r.get('msg'));
        }

      }else{
        	msg = '获取价目表信息失败 : '+res.getBody();
      }
    }


    public void syncToOutdoor(){

          msg = '';
          isSuc = false;
          try{

              if(poi.Status__c != '已批准')throw new DmlException('未审批通过不能同步!') ;

              User u = [select Id, ExuserCode__c from User where Id =:UserInfo.getUserId()];
               String operator = u.ExuserCode__c;

               if(operator == null ) throw new DmlException('请联系管理员维护工号!') ;
               String corpcode =  ImportObject.getPicklistValues('Contract__c', 'CorpCode__c', false).get(poi.Company__c);
               if(corpcode == null )throw new DmlException('请选择出库公司!'); 


            List<BorrowGoodsDetail__c> bgList = [select Id ,Quantity__c,BorrowDetail__r.Name,BorrowDetail__c,Inventory__c,Inventory__r.ProductName__c,BorrowDetail__r.Customer__r.AccountNumber,Inventory__r.NCCode__c 
             from  BorrowGoodsDetail__c where BorrowDetail__c =:backId  ];

             List<InstrumentDeliverySyncUtil.OutdoorBean> ouL  = new List<InstrumentDeliverySyncUtil.OutdoorBean>();

             Decimal t = 0;
             for( BorrowGoodsDetail__c bg : bgList){

                InstrumentDeliverySyncUtil.OutdoorBean ob = new InstrumentDeliverySyncUtil.OutdoorBean();

                ob.sfmanid = poi.Id;
                ob.sflistid = bg.Id;
                ob.cbizid = poi.Owner.Name;
                //cdptid = ida.Owner.;
                ob.dbilldate = System.now().format('yyyy-MM-dd');
                ob.planrecivedate = System.now().format('yyyy-MM-dd');
                ob.operator =  operator ;
                ob.pk_corp = corpcode;
                //vnote = np.Remarks__c;
                ob.totalnum = '0';
                ob.recvnotes = poi.Destination__c ;
                ob.vnote = poi.Note__c ;
                ob.zdcode = poi.UseHospital__r.AccountNumber == null ? '' : poi.UseHospital__r.AccountNumber  ;
                ob.isentity ='是';// ida.PhysicalDelivery__c;

                ob.cgphone = poi.ConsigneeCall__c;
                ob.nextaction = '';
                ob.nextbilltype =  '' ;
                ob.custcode = poi.UseHospital__r.AccountNumber;

                ob.invcode = bg.Inventory__r.NCCode__c;

                ob.ts = System.now().format('yyyy-MM-dd HH:mm:ss');

                ob.sapply_hid = poi.Id;

                ob.sapply_bid = bg.Id;
                ob.isInstallsale = '否';
                ob.applynum = bg.Quantity__c == null ? '' : String.valueOf(bg.Quantity__c );
                t += bg.Quantity__c == null ? 0 : bg.Quantity__c;
                // pk_defdoc10 = '0001A1100000010658ZQ';
                // vuserdef10 = '仪器申请';
                ob.pk_defdoc10 = '';
                ob.vuserdef10 = '';
                ouL.add(ob);

              } 
              for ( InstrumentDeliverySyncUtil.OutdoorBean ob :ouL ) {
                  ob.totalnum = String.valueOf(t);
              }

              Map<String,String >resM = InstrumentDeliverySyncUtil.syncOutdoor(ouL);

              if(resM.get('code') == '0'){

                  poi.IsSycToNc__c = true;
                  poi.ResultMsg__c = resM.get('msg');
                  update poi;

                  isSuc = true;

              }else{
                  throw new DmlException(resM.get('msg'));
              }
          }catch(Exception e ){

              msg = e.getMessage();

          }
            

    }

    public void sync(){
      msg = '';
      isSuc = false;
    	try{

    		Map<String,Object> dataMap = (Map<String,Object> )JSON.deserializeUntyped(EncodingUtil.urlDecode( syncJson, 'UTF-8'));

        Set<String> nccodes = new Set<String>();
        List<Object> noprices = (List<Object>) dataMap.get('noprice');

        for(Object o : noprices){
            nccodes.add(String.valueOf(o));
        }
    		List<ProductBean> pList = new List<ProductBean>();
        List<BorrowGoodsDetail__c> bgList = [select Id ,BorrowDetail__r.Name,BorrowDetail__c,Inventory__c,Inventory__r.ProductName__c,BorrowDetail__r.Customer__r.AccountNumber,Inventory__r.NCCode__c 
           from  BorrowGoodsDetail__c where BorrowDetail__c =:backId  ];


	    	for( BorrowGoodsDetail__c bg : bgList){

            if(nccodes.contains(bg.Inventory__r.NCCode__c)) continue;
	    	   	ProductBean pb = new ProductBean();
	    	   	pb.tjdate = System.now().format('yyyy-MM-dd');
	    	   	pb.jmcode = String.valueOf(dataMap.get('jmcode'));
	    	   //	pb.jmname = String.valueOf(dataMap.get('jmname'));
	    	   	checkNull(pb.jmcode,String.valueOf(dataMap.get('jmname'))  +'不存在!');
	    	   	pb.corpcode = String.valueOf(dataMap.get('corpcode'));
	    	   	checkNull(pb.corpcode,String.valueOf(dataMap.get('jmname'))  +'不存在!');
	    	   	pb.dreceiptdate = System.now().format('yyyy-MM-dd');
	    	   	pb.dexpiredate = System.now().addMonths(1).format('yyyy-MM-dd');
	    	   	pb.cadjpriceid = bg.BorrowDetail__c;
	    	   	pb.cadjprice_bid = bg.Id ; 
	    	   	pb.invcode = bg.Inventory__r.NCCode__c;
	    	   	checkNull(pb.invcode,bg.Inventory__r.ProductName__c +'不存在产品编码!');
	    	   	pb.custcode = bg.BorrowDetail__r.Customer__r.AccountNumber;
	    	   	checkNull(pb.custcode,'对方单位未维护客户编码!');
            pb.fadjtype = 1;
	    	   	pb.jgtype = '成交价';
	    	   	pb.newprice = '0.01';
            //dtstoptime;//失效时间止dvalidate;//有效日期起dtstarttime;//有效时间起
            pb.dtstoptime =  System.now().format('HH:mm:ss');
            pb.dvalidate = System.now().format('yyyy-MM-dd');//
            pb.dtstarttime = System.now().format('HH:mm:ss');

	    	   	pb.baseprice = '0'; 
	    	   	pb.jgzs = '1';
	    	   	pb.jgjc = '0.01';
	    	   	pb.ts = System.now().format('yyyy-MM-dd HH:mm:ss');
	    	   	pb.created_by = Owner.Name;
	    	   	pb.sub_corp_manager = Owner.Manager.Name;
            pb.vmemo= bg.BorrowDetail__r.Name;
	    	   	pList.add(pb);


	    	 }
         msg = 'OK';
         if(!nccodes.isEmpty() ){
            msg  = syncProductPrice(String.valueOf(dataMap.get('corpcode')),new List<String>(nccodes) );
         }
         if(msg != 'OK')return;
	    	 if(pList.size()> 0  ) {


                Map<String ,List<ProductBean>>temp = new Map<String ,List<ProductBean>>();
                temp.put('data',pList);

                String body = JSON.serialize(temp);
                System.debug(body);
                HttpRequest req = new HttpRequest();
                req.setBody(body);
                //return body;
                req.setMethod('POST');
                req.setHeader('Content-Type','text/plain');
                // 接口写在自定义标签的quoteUrl里面
                //System.Label.quoteUrl
                //调价单
                String url = Label.QueryTjdPutUrl;
                req.setEndpoint(url);

                System.debug('+++'+ body);
                
                HttpResponse res = Utils.postRequest(req, 1);
                 System.debug('+++'+res.getBody());
             
                if (res.getStatusCode() == 200) {
                    Map<String,Object> r = new Map<String,Object>();
                    //如果是测试
                    if(Test.isRunningTest()){

                        Map<String,Object>  resBody= new Map<String,Object>();
                      resBody.put('code','0');
                      resBody.put('result','{\"result_msg\":\"操作成功！\",\"result\":1,\"data\":{\"ts\":\"2018-01-04 16:24:18\"}}');
                        r =  resBody;
                    }else{
                         r  = (Map<String,Object> ) JSON.deserializeUntyped(res.getBody());
       
                    }
                   // return res.getBody();
                     if(r.get('code') == 0 || r.get('code') == '0'){
                        Map<String,Object> rs = (Map<String,Object>) JSON.deserializeUntyped(((String)r.get('result')));
                    
                       msg = '系统提示:';
                       msg +=  rs.get('result') == 0 ? '同步失败:' +(String) rs.get('result_msg')  :'同步成功';
                       if (rs.get('result') == 1 ) {
                
                          
                           msg = 'OK';
                           
                       }
                         
                     }else{
                      msg +=  '系统提示:' + (String)r.get('msg') ;
                     }


                } else {
                    msg +=  '系统错误:'+res.toString()+',请联系系统管理员!';
                }

            }
            System.debug(msg);
            if(msg != 'OK')throw new DmlException(msg);

                try {
                    poi.IsSycToNc__c = true;
                    poi.NCPriceDialog__c = String.valueOf(dataMap.get('jmname') )+String.valueOf(dataMap.get('jmcode') );
                    update poi ; 
                    msg = '同步成功!';
                    isSuc = true;
                }
                catch (Exception e) {
                   
                   msg = '同步成功!回写记录失败!'+ e.getMessage(); 
                   return;
                }
               
            
           
              

      }catch(Exception e){

        msg = '同步失败:'+e.getMessage();
        System.debug(msg);

      }
        
    }



    private String  syncProductPrice(String corpcode , List<String> invc ){
         String url = Label.NCExchangeInterface;//'https://esb.maccura.com:9088/api/Domain/univer/dbbus/search';
        
        Map<String, String >dataMap = new Map<String,String>();
        //测试 NCTEST
        dataMap.put('source',source);
        dataMap.put('tag',updateTag );

        //dataMap.put('pk','\''+String.join(accPks,'\',\'')+'\'');
        dataMap.put('gs',corpcode);
        dataMap.put('invc','\''+String.join(invc,'\',\'')+'\'');


        //Map<String,String> data = new Map<String,String>();
       // data.put('data', JSON.serialize(dataMap));

        System.debug(JSON.serialize(dataMap));        

        //请求
        HttpRequest req = new HttpRequest();
        //req.setBody(JSON.serialize(data) );
        req.setMethod('POST');
        //req.setHeader('Content-Type','text/plain');
        //req.setEndpoint(url);
        req.setHeader('Content-Type','application/x-www-form-urlencoded ; charset=utf-8');
        req.setEndpoint(url+'?data='+JSON.serialize(dataMap));
        HttpResponse res = Utils.postRequest(req, 2);
        String sycmsg = '';
      ///返回结果处理
        if (res.getStatusCode() == 200) {
            System.debug(res.getBody());
            Map<String,Object> r = null;
              //如果是测试
                if(Test.isRunningTest()){
                  Map<String,Object>  resBody= new Map<String,Object>();
                  resBody.put('code','0');
                  resBody.put('result','{\"result\":\"该SQL语句影响的记录有1条\",\"code\":\"0\",\"msg\":\"success\"}');
                    r =  resBody;
                }else{
                  r= (Map<String,Object> ) JSON.deserializeUntyped(res.getBody());
                }
            if(r.get('code') == 0 || r.get('code') == '0'){
                Map<String,Object> rs = (Map<String,Object>) JSON.deserializeUntyped(((String)r.get('result')));
              if( (rs.get('code') == 0 || rs.get('code') == '0' ) ){
                    
                    sycmsg = 'OK';


               }else{
                    sycmsg = '同步失败: '+rs.get('result')+rs.get('msg');
               }

            }else{

                sycmsg = '同步失败 : '+String.valueOf(r.get('msg'));
            }

        }else{
             sycmsg = '同步失败 : '+res.getBody();
        } 
        return sycmsg;


    }
    private void setErr(String message){
    	isErr =true;
    	throw new ControllerException(message);
    }

    public class BrorrowBean{
        public String productId;
        public String productName;
        public String brand;
        public String spec;
        public String nccode;
        public String serialno;
        public Decimal num;
        public String bid;//明细id 
        public String cate1;
        public String unit ;

        public BrorrowBean(BorrowGoodsDetail__c bo ){
            productId = bo.Inventory__c ;
            productName  = bo.Inventory__r.ProductName__c;
            brand = bo.Inventory__r.Brand__c;
            spec = bo.Inventory__r.Spec__c;
            nccode = bo.Inventory__r.NCCode__c;
            serialno = bo.Inventory__r.SerialNo__c;
            num = bo.Quantity__c;
            bid = bo.Id;
            cate1 = bo.Inventory__r.Category1__c;
            unit = bo.Inventory__r.Unit__c;
        }
         public BrorrowBean(Product__c  bo ){
            productId = bo.Id  ;
            productName  = bo.ProductName__c;
            brand = bo.Brand__c;
            spec = bo.Spec__c;
            nccode = bo.NCCode__c;
            serialno = bo.SerialNo__c;
            cate1 = bo.Category1__c;
            unit = bo.Unit__c;
        }


    }

    public class ProductBean{
    	public String tjdate;//调价日期
    	public String jmcode;//价目表编码
    	//public String jmname;//价目表名称
    	public String corpcode; //公司编码 
    	//public String corpname; //公司名称

    	public String dreceiptdate; //有效期从
    	public String dexpiredate; //有效期至
    	public String cadjpriceid; //调价单主表pk
    	public String cadjprice_bid; //调价单子表pk 

    	public String invcode; //产品编码
    	public String custcode;//客户编码
    	public String jgtype;//价格项
    	public String newprice; //新建价格
    	public String baseprice; //基价
      public Integer fadjtype ;//调价单类型-- 1:[调促销策略]-- 0:[调基价]-- 2:[调基准折扣]
            //dtstoptime;//失效时间止dvalidate;//有效日期起dtstarttime;//有效时间起
      public String dtstoptime ;//失效时间止
      public String dvalidate; //有效日期起
      public String dtstarttime;  //有效时间起

    	public String jgzs; //价格指数 
    	public String jgjc ; //价格加成
    	public String ts; 

    	public String created_by;//制单人
    	public String sub_corp_manager;//审核人

      public String vmemo;//备注



    }


}